package com.mrd.frame.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mrd.base.utils.JsonBinder;
import com.mrd.frame.domain.Order;
import com.mrd.frame.domain.params.BaseDto;
import com.mrd.frame.service.OrderService;

/**
* CopyRight: 佛航集团
* Author: han
* Date: 2017-06-30 14:35:36
*/
@Controller
public class OrderController {
         
     private static final Log logger = LogFactory
			.getLog(OrderController.class);
     @Autowired
     OrderService orderService;
	
    @RequestMapping(value = "/Order", method = RequestMethod.GET)
 	public String accessConfig(){
 		return "/order/Order";
 	}
     
	/**
	 * @Description: 获取分页列表
	 * @author: han
	 * @date: 2017-06-30 14:35:36
	 * @return void
	 */
    @ResponseBody
    @RequestMapping(value = "/Order/getPageList")
	public String getPageList(@ModelAttribute Order order, @ModelAttribute BaseDto bdt) {
		PageInfo<Order> pi = null;
		String result = "";
		try {
	    	PageHelper.startPage(bdt.page,bdt.pageSize);
	    	List<Order> orderList = orderService.getPageList(order);
	    	pi = new PageInfo<Order>(orderList);
	    	bdt.setTotal((int) pi.getTotal());
	    	bdt.setRows(orderList);
			JsonBinder binder = JsonBinder.buildNormalBinder();
			binder.setDateFormat("yyyy-MM-dd HH:mm:ss");
			result = binder.toJson(bdt);
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
		}
    	return result;
	}

	/**
	 * @Description:根据ID获取详情信息
	 * @author:han
	 * @Date: 2017-06-30 14:35:36
	 * @return void
	 */
	public void getById() {
		try {
//			String id = this.getRequest().getParameter("id");
//			Map<String, Object> map = new HashMap<String, Object>();
//			OrderDto orderDto = this.orderService.getById(id);
//			map.put("objDetail", orderDto);
//			this.writeJson(map);
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
		}
	}
	
}